<!--
 * @Author: Charlie/彭旺
 * @email: 413157399@qq.com
 * @Date: 2022-06-17 15:40:28
-->
<template>
  <el-dialog
    :append-to-body="true"
    :close-on-click-modal="false"
    :before-close="cancel"
    :visible.sync="dialog"
    title="编辑"
    width="600px"
  >
    {{ isAdd }}
    <el-form ref="form" :model="form" size="small" label-width="100px">
      <el-form-item label="等级名称">
        <el-input v-model="form.name" style="width: 370px" disabled />
      </el-form-item>
      <el-form-item label="会员等级">
        <el-input v-model="form.grade" style="width: 370px" disabled />
      </el-form-item>
      <el-form-item label="数量">
        <el-input v-model.number="form.number" style="width: 370px" />
      </el-form-item>
      <el-form-item label="单位">
        <el-input v-model="form.unit" style="width: 370px" disabled />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="text" @click="cancel">取消</el-button>
      <el-button :loading="loading" type="primary" @click="doEdit"
        >确认</el-button
      >
    </div>
  </el-dialog>
</template>

<script>
import { edit } from "@/api/yxSystemUserLevel";
export default {
  props: {
    isAdd: {
      type: Boolean,
      required: true,
    },
  },
  data() {
    return {
      loading: false,
      dialog: false,
      form: {},
    };
  },
  methods: {
    cancel() {
      this.dialog = false;
    },
    doEdit() {
      this.loading = true;
      edit(this.form)
        .then((res) => {
          this.$notify({
            title: "修改成功",
            type: "success",
            duration: 2500,
          });
          this.dialog = false;
          this.loading = false;
          this.$parent.getList();
        })
        .catch((err) => {
          this.loading = false;
          console.log(err.response.data.message);
        });
    },
  },
};
</script>